package com.pshcp.api;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.external.hospital.ap.Hospital2UserApService;
import com.external.hospital.ap.UserApManager;
import com.external.hospital.ap.domain.SavePatientDTO;
import com.external.hospital.ap.domain.SavePatientInquirerDTO;
import com.external.hospital.chatmessage.Hospital2ChatMessageService;
import com.external.hospital.chatmessage.domain.ConnectParamsDTO;
import com.external.hospital.chatmessage.domain.FinishConsultSessionDTO;
import com.external.hospital.chatmessage.domain.InitConsultSessionDTO;
import com.external.hospital.chatmessage.domain.SendPatientsMedicalRecordDTO;
import com.external.hospital.chatmessage.domain.SendPatientsMedicalRecordRes;
import com.external.hospital.chatmessage.domain.SendSysMessageDTO;
import com.external.hospital.chatmessage.domain.SendSysMessageRes;
import com.external.hospital.chatmessage.domain.UploadMediaDTO;
import com.external.hospital.chatmessage.domain.UploadMediaRes;
import com.framework.base.ResultBuilder;
import com.framework.base.ResultDTO;
import com.framework.common.config.CustomConf;
import com.framework.exception.BizException;
import com.framework.logaop.Log;
import com.framework.logaop.LogSourceEnum;
import com.framework.logaop.LogTypeEnum;
import com.framework.thread.ReqComTool;
import com.framework.tool.CommonTool;
import com.framework.util.DateUtil;
import com.google.common.collect.Lists;
import com.pshcp.ao.chatmessage.ConnectParamsAO;
import com.pshcp.ao.chatmessage.FinishConsultSessionAO;
import com.pshcp.ao.chatmessage.InitConsultSessionAO;
import com.pshcp.ao.chatmessage.SendMessageAO;
import com.pshcp.ao.chatmessage.SendScheduleIMAO;
import com.pshcp.ao.chatmessage.SendShareArticleMessageAO;
import com.pshcp.ao.chatmessage.SendSysMessageAndPatientsMedicalRecordAO;
import com.pshcp.ao.chatmessage.SendSystemMessageIMAO;
import com.pshcp.ao.chatmessage.UploadMediaAO;
import com.pshcp.common.tool.PhotoTools;
import com.pshcp.domain.model.*;
import com.pshcp.manager.messagenotification.MessageNotificationDTO;
import com.pshcp.manager.messagenotification.MessageNotificationManager;
import com.pshcp.service.*;
import com.pshcp.tool.ChatMessageTool;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @Description: TODO
 * @Author: xiaoche
 * @Date: 2022/12/11 16:06
 */
@Api(tags = {"通用接口-IM(仅做转发)"})
@Slf4j
@RestController
@RequestMapping("/api/im/chatMessage")
public class ChatMessageAPI {

    @Autowired
    private Hospital2ChatMessageService chatMessageService;

    @Autowired
    private OnlineSessionService onlineSessionService;

    @Autowired
    private PatientOnlineMedicalRecordsService patientOnlineMedicalRecordsService;

    @Autowired
    private PatientService patientService;

    @Autowired
    private PatientUserService patientUserService;

    @Autowired
    private DoctorArticleService doctorArticleService;

    @Autowired
    private DoctorService doctorService;
    @Autowired
    private DoctorArticleNotificationPatientService doctorArticleNotificationPatientService;

    @Autowired
    private MessageNotificationManager messageNotificationManager;

    @Autowired
    private OrderRegService orderRegService;


    @Autowired
    private Hospital2UserApService hospital2UserApService;


    @Autowired
    private Hospital2UserApService userApService;

    @Autowired
    private CustomConf customConf;

    @Autowired
    private UserApManager userApManager;
    @Autowired
    private PatientOnlineOrderService patientOnlineOrderService;

    @ApiOperation("获取IM连接配置")
    @Log(source = LogSourceEnum.APP, type = LogTypeEnum.SELECT, desc = "获取IM连接配置")
    @PostMapping("getConnectParams")
    public JSONObject getConnectParams(@RequestBody ConnectParamsAO connectParamsAO) {
        ConnectParamsDTO connectParamsDTO = CommonTool.copyProperties(connectParamsAO, ConnectParamsDTO.class);
        return chatMessageService.connectParams(connectParamsDTO);
    }

    @ApiOperation("初始化咨询会话")
    @Log(source = LogSourceEnum.APP, type = LogTypeEnum.UPDATE, desc = "初始化咨询会话")
    @PostMapping("initConsultSession")
    public JSONObject initConsultSession(@RequestBody InitConsultSessionAO initConsultSessionAO) throws Exception {
        Patient patient = patientService.findById(initConsultSessionAO.getPatientId());
        if (patient == null) {
            CommonTool.throwBizException("90000007", "check patient id is right?");
        }
        PatientUser patientUser = patientUserService.findById(patient.getPatientUserId());
        SavePatientDTO savePatientDTO = ChatMessageTool.buildSavePatientDTO(customConf, patientUser);
        userApService.savePatient(savePatientDTO);

        SavePatientInquirerDTO savePatientInquirerDTO = ChatMessageTool.buildSavePatientInquirerDTO(patient);
        userApService.savePatientInquirer(savePatientInquirerDTO);

        Map<String, String> params = new HashMap<>();
        params.put("doctorId", initConsultSessionAO.getDoctorId().toString());
        params.put("patientId", initConsultSessionAO.getPatientId().toString());
        params.put("source", "5");
        params.put("firstRecom", "");
        hospital2UserApService.user2ap2patientSync2addPersonalDoctor(params);

        InitConsultSessionDTO initConsultSessionDTO = CommonTool.copyProperties(initConsultSessionAO, InitConsultSessionDTO.class);
        initConsultSessionDTO.setUserId(patient.getPatientUserId());
        return chatMessageService.initConsultSession(initConsultSessionDTO);
    }

    @ApiOperation("结束咨询会话")
    @Log(source = LogSourceEnum.APP, type = LogTypeEnum.UPDATE, desc = "结束咨询会话")
    @PostMapping("finishConsultSession")
    public JSONObject finishConsultSession(@RequestBody FinishConsultSessionAO finishConsultSessionAO) {
        FinishConsultSessionDTO finishConsultSessionDTO = CommonTool.copyProperties(finishConsultSessionAO, FinishConsultSessionDTO.class);
        // 添加推送消息
        OnlineSession onlineSession = onlineSessionService.getOnlineSessionByPatientOnlineOrderId(finishConsultSessionAO.getPatientOnlineOrderId());
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("content", "本次会话已结束，如有问题没有咨询完成，可再次向医生发起咨询~");
        jsonObject.put("doctorId", onlineSession.getDoctorId());
        jsonObject.put("doctorName", onlineSession.getDoctorName());
        Doctor doctor = doctorService.findById(onlineSession.getDoctorId());
        jsonObject.put("headUrl", PhotoTools.getFullPath(customConf.getFileUrl(), doctor.getHeadPhoto()));
        jsonObject.put("patientName", onlineSession.getPatientName());
        jsonObject.put("msgType", "10008");
        jsonObject.put("origin", "1");
        jsonObject.put("patientId", onlineSession.getPatientId());
        jsonObject.put("askType", 1);
        jsonObject.put("patientOnlineOrderId", onlineSession.getPatientOnlineOrderId());
        chatMessageService.sendMessageByType(jsonObject);
        return chatMessageService.finishConsultSession(finishConsultSessionDTO);
    }

    @ApiOperation("上传素材")
    @Log(source = LogSourceEnum.APP, type = LogTypeEnum.UPDATE, desc = "上传素材")
    @PostMapping("uploadMedia")
    public UploadMediaRes uploadMedia(UploadMediaAO uploadMediaAO, @ApiParam(value = "附件") @RequestPart("file") MultipartFile file) throws BizException {
        UploadMediaDTO uploadMediaDTO = ChatMessageTool.buildUploadMediaDTO(uploadMediaAO, file);
        return chatMessageService.uploadMedia(uploadMediaDTO);
    }

    @ApiOperation("发送消息")
    @Log(source = LogSourceEnum.APP, type = LogTypeEnum.UPDATE, desc = "发送消息")
    @PostMapping("sendMessage")
    public JSONObject sendMessage(@RequestBody Map<String, String> params) {
        // 如果是医生发送给患者，获取patientOrderId 修改状态
        Map<String, Object> message = JSON.parseObject(params.get("message"), new TypeReference<HashMap<String, Object>>() {});
        if("1".equals(params.get("origin")) && message.get("patientOnlineOrderId") != null){  // 医生给患者
            Long patientOnlineOrderId = Long.parseLong(message.get("patientOnlineOrderId").toString());
            // 修改是否回复
            onlineSessionService.updateOnlineSessionIsReply(patientOnlineOrderId);
        }
        return chatMessageService.sendMessage(params);
    }

    @ApiOperation("获取消息列表")
    @Log(source = LogSourceEnum.APP, type = LogTypeEnum.SELECT, desc = "获取IM消息(分页)")
    @PostMapping("getSendMessagePage")
    public JSONObject getSendMessagePage(@RequestBody Map<String, String> params) throws Exception {
        return chatMessageService.getSendMessageList(params);
    }

    @ApiOperation("发送系统消息和病情描述")
    @Log(source = LogSourceEnum.APP, type = LogTypeEnum.UPDATE, desc = "发送系统消息和病情描述")
    @PostMapping("sendSysMessageAndPatientsMedicalRecord")
    public ResultDTO<Long> sendPatientsMedicalRecord(@RequestBody SendSysMessageAndPatientsMedicalRecordAO sendSysMessageAndPatientsMedicalRecordAO) throws BizException {
        CommonTool.checkObj(sendSysMessageAndPatientsMedicalRecordAO.getPatientOnlineOrderId(), "90000006");
        PatientOnlineMedicalRecords medicalRecords = patientOnlineMedicalRecordsService.findByOnlineOrderId(sendSysMessageAndPatientsMedicalRecordAO.getPatientOnlineOrderId());
        OnlineSession onlineSession = onlineSessionService.getOnlineSessionByPatientOnlineOrderId(sendSysMessageAndPatientsMedicalRecordAO.getPatientOnlineOrderId());
        Patient patient = patientService.findById(onlineSession.getPatientId());
        CommonTool.checkObj(onlineSession, "90000007");
        CommonTool.checkObj(patient, "90000007");
        CommonTool.checkObj(medicalRecords, "90000007");
        SendSysMessageDTO sendSysMessageDTO = ChatMessageTool.buildSendSysMessage(onlineSession);
        SendSysMessageRes sendSysMessageRes = chatMessageService.sendSysMessage(sendSysMessageDTO);
        if (sendSysMessageRes.getCode() != 0) {
            return ResultBuilder.failure(sendSysMessageRes.getCode() + "", sendSysMessageRes.getMsg());
        }
        Doctor doctor = doctorService.findById(onlineSession.getDoctorId());
        SendPatientsMedicalRecordDTO sendPatientsMedicalRecordDTO = ChatMessageTool.buildSendPatientsMedicalRecord(onlineSession, patient, medicalRecords,
                sendSysMessageAndPatientsMedicalRecordAO, doctor, customConf);
        SendPatientsMedicalRecordRes sendPatientsMedicalRecordRes = chatMessageService.sendPatientsMedicalRecord(sendPatientsMedicalRecordDTO);
        if (sendPatientsMedicalRecordRes.getCode() != 0) {
            return ResultBuilder.failure(sendPatientsMedicalRecordRes.getCode() + "", sendPatientsMedicalRecordRes.getMsg());
        }
        // 推送IM系统消息
        userApManager.sendSystemMessage(sendPatientsMedicalRecordDTO.getDoctorId(), onlineSession.getPatientUserId(), null);
        userApManager.sendSystemMessage(sendPatientsMedicalRecordDTO.getDoctorId(), sendPatientsMedicalRecordDTO.getPatientId(), null);
        // 添加系统消息
        messageNotificationManager.sendMessageNotification(ChatMessageTool.buildSendSysMessageAndPatientsMedicalRecord2MessageNotificationDTO(onlineSession.getPatientOnlineOrderId(),
                sendPatientsMedicalRecordDTO));

        return ResultBuilder.success(null);
    }

    @ApiOperation("根据消息类型发送消息")
    @Log(source = LogSourceEnum.APP, type = LogTypeEnum.ADD, desc = "根据消息类型发送消息")
    @PostMapping("sendMessageByType")
    public JSONObject sendMessageByType(@RequestBody JSONObject jsonObject) throws Exception {
        return chatMessageService.sendMessageByType(jsonObject);
    }

    @ApiOperation("发送文章推送患者(IM)")
    @Log(source = LogSourceEnum.APP, type = LogTypeEnum.UPDATE, desc = "发送文章推送患者(IM)")
    @PostMapping("sendArticleIM")
    public ResultDTO<Long> sendArticleIM(@RequestBody SendShareArticleMessageAO sendShareArticleMessageAO) throws Exception {
        DoctorArticle doctorArticle = doctorArticleService.findById(sendShareArticleMessageAO.getArticleId());
        CommonTool.checkObj(doctorArticle, "90000007");
        if (StringUtils.isBlank(sendShareArticleMessageAO.getPatientIds())) {
            return ResultBuilder.success(null);
        }
        String patientIds = sendShareArticleMessageAO.getPatientIds();
        String[] patientIdArr = StringUtils.split(patientIds, ",");
        List<Long> patientIdList = Lists.newArrayList();
        for (String patientId : patientIdArr) {
            if (StringUtils.isBlank(patientId)) {
                continue;
            }
            patientIdList.add(Long.valueOf(patientId));
        }
        if (CollectionUtils.isEmpty(patientIdList)) {
            return ResultBuilder.success(null);
        }
        Doctor doctor = doctorService.findById(ReqComTool.getUserId());
        List<DoctorArticleNotificationPatient> doctorArticleNotificationPatientList = doctorArticleNotificationPatientService.getDoctorArticleNotificationPatientList(doctorArticle.getId(), patientIdList);
        List<Patient> patientList = patientService.findByIds(patientIdList);
        Map<Long, Patient> patientMap = patientList.stream().collect(Collectors.toMap(Patient::getId, Function.identity(), (key1, key2) -> key2));
        List<DoctorArticleNotificationPatient> list = ChatMessageTool.buildShareDoctorArticleNotificationPatientList(doctorArticleNotificationPatientList, sendShareArticleMessageAO.getArticleId(), patientIdList);
        for (DoctorArticleNotificationPatient doctorArticleNotificationPatient : list) {
            Patient patient = patientMap.get(doctorArticleNotificationPatient.getPatientId());
            if (patient == null) {
                continue;
            }
            JSONObject jsonObject1 = new JSONObject();
            JSONObject content1 = new JSONObject();
            content1.put("id", doctorArticle.getId());
            content1.put("link", doctorArticle.getLink());
            content1.put("title", doctorArticle.getTitle());
            content1.put("type", doctorArticle.getType());
            content1.put("content", doctorArticle.getContent());
            content1.put("doctorName", doctor.getName());
            content1.put("mediLevel", doctor.getMediLevel());
            jsonObject1.put("content", content1.toJSONString());
            jsonObject1.put("doctorId", doctor.getId());
            jsonObject1.put("doctorName", doctor.getName());
            jsonObject1.put("headUrl", PhotoTools.getFullPath(customConf.getFileUrl(), doctor.getHeadPhoto()));
            jsonObject1.put("msgType", "10017");
            jsonObject1.put("origin", "1");
            jsonObject1.put("patientId", patient.getId());
            jsonObject1.put("patientName", patient.getName());
            jsonObject1.put("askType", sendShareArticleMessageAO.getAskType());
            jsonObject1.put("patientOnlineOrderId", sendShareArticleMessageAO.getPatientOnlineOrderId());
            chatMessageService.sendMessageByType(jsonObject1);
            // 推送IM系统消息
            userApManager.sendSystemMessage(doctor.getId(), patient.getPatientUserId(), "4");
            userApManager.sendSystemMessage(doctor.getId(), patient.getId(), "4");
            messageNotificationManager.sendMessageNotification(ChatMessageTool.buildSendArticleIM2MessageNotificationDTO(patient.getPatientUserId(), doctorArticle));
        }
        return ResultBuilder.success(null);
    }

    @ApiOperation("发送文章推送患者(通知)")
    @Log(source = LogSourceEnum.APP, type = LogTypeEnum.UPDATE, desc = "发送文章推送患者(通知)")
    @PostMapping("sendArticleMessageNotification")
    public ResultDTO<Long> sendArticleMessageNotification(@RequestBody SendShareArticleMessageAO sendShareArticleMessageAO) throws Exception {
        DoctorArticle doctorArticle = doctorArticleService.findById(sendShareArticleMessageAO.getArticleId());
        CommonTool.checkObj(doctorArticle, "90000007");
        if (StringUtils.isBlank(sendShareArticleMessageAO.getPatientIds())) {
            return ResultBuilder.success(null);
        }
        String patientIds = sendShareArticleMessageAO.getPatientIds();
        String[] patientIdArr = StringUtils.split(patientIds, ",");
        List<Long> patientIdList = Lists.newArrayList();
        for (String patientId : patientIdArr) {
            if (StringUtils.isBlank(patientId)) {
                continue;
            }
            patientIdList.add(Long.valueOf(patientId));
        }
        if (CollectionUtils.isEmpty(patientIdList)) {
            return ResultBuilder.success(null);
        }
        List<Patient> patients = patientService.findByIds(patientIdList);
        Map<Long, Patient> patientMap = patients.stream().collect(Collectors.toMap(Patient::getId, Function.identity(), (key1, key2) -> key2));
        List<DoctorArticleNotificationPatient> doctorArticleNotificationPatientList = doctorArticleNotificationPatientService.getDoctorArticleNotificationPatientList(doctorArticle.getId(), patientIdList);
        List<DoctorArticleNotificationPatient> list = ChatMessageTool.buildShareDoctorArticleNotificationPatientList(doctorArticleNotificationPatientList, sendShareArticleMessageAO.getArticleId(), patientIdList);
        for (DoctorArticleNotificationPatient doctorArticleNotificationPatient : list) {
            // 添加系统消息
            Patient patient = patientMap.get(doctorArticleNotificationPatient.getPatientId());
            MessageNotificationDTO messageNotificationDTO = ChatMessageTool.buildDoctorArticleNotificationPatientMessageNotification(doctorArticle, patient.getPatientUserId());
            messageNotificationManager.sendMessageNotification(messageNotificationDTO);
        }
        // 推送消息
        return ResultBuilder.success(null);
    }

    @ApiOperation("发送系统消息IM")
    @Log(source = LogSourceEnum.APP, type = LogTypeEnum.UPDATE, desc = "发送系统消息IM")
    @PostMapping("sendSystemMessageIM")
    public ResultDTO<Long> sendSystemMessageIM(@RequestBody SendSystemMessageIMAO sendSystemMessageIMAO) throws Exception {
        String patientIds = sendSystemMessageIMAO.getPatientIds();
        String[] patientIdArr = StringUtils.split(patientIds, ",");
        List<Long> patientIdList = Lists.newArrayList();
        for (String patientId : patientIdArr) {
            if (StringUtils.isBlank(patientId)) {
                continue;
            }
            patientIdList.add(Long.valueOf(patientId));
        }
        if (CollectionUtils.isEmpty(patientIdList)) {
            return ResultBuilder.success(null);
        }
        userApManager.batchSendSystemMessage(sendSystemMessageIMAO.getDoctorId(), patientIdList, sendSystemMessageIMAO.getType());
        return ResultBuilder.success(null);
    }


    @ApiOperation("发送患者诊前加号(通知)")
    @Log(source = LogSourceEnum.APP, type = LogTypeEnum.UPDATE, desc = "发送文章推送患者(通知)")
    @PostMapping("sendScheduleNotification")
    public ResultDTO<Long> sendScheduleNotification(@RequestBody SendScheduleIMAO sendScheduleIMAO) throws Exception {
        CommonTool.checkObj(sendScheduleIMAO.getId(), "90000012");
        OrderReg orderReg = orderRegService.findById(sendScheduleIMAO.getId());
        CommonTool.checkObj(orderReg, "90000007");
        MessageNotificationDTO messageNotificationDTO = ChatMessageTool.buildDoctorScheduleNotificationPatientMessageNotification(orderReg, orderReg.getPatientUserId());
        // 推送消息
        messageNotificationManager.sendMessageNotification(messageNotificationDTO);
        return ResultBuilder.success(null);
    }

    @ApiOperation("发送患者诊前加号(IM)")
    @Log(source = LogSourceEnum.APP, type = LogTypeEnum.UPDATE, desc = "发送患者诊前加号(IM)")
    @PostMapping("sendScheduleIM")
    public ResultDTO<Long> sendScheduleIM(@RequestBody SendScheduleIMAO sendScheduleIMAO) throws Exception {
        CommonTool.checkObj(sendScheduleIMAO.getId(), "90000012");
        OrderReg orderReg = orderRegService.findById(sendScheduleIMAO.getId());
        CommonTool.checkObj(orderReg, "90000007");
        Patient patient = patientService.findById(orderReg.getPatientId());
        Doctor doctor = doctorService.findById(orderReg.getDoctorId());
        JSONObject jsonObject = new JSONObject();
        JSONObject content = new JSONObject();
        content.put("hosName", orderReg.getHosName());
        content.put("doctorName", orderReg.getDoctorName());
        content.put("address", orderReg.getAddress());
        content.put("patientName", patient.getName());  // 患者姓名
        content.put("cost", orderReg.getCost());  // 费用
        content.put("dataId", orderReg.getId());
        Date date = DateUtil.parse(orderReg.getExpectStime(), "yyyy-MM-dd HH:mm:ss");
        String expectTime = new SimpleDateFormat("yyyy-MM-dd ahh:mm").format(date);
        content.put("expectTime", expectTime);   // 就诊时间
        jsonObject.put("content", content.toJSONString());
        jsonObject.put("doctorId", orderReg.getDoctorId());
        jsonObject.put("doctorName", doctor.getName());
        jsonObject.put("headUrl", PhotoTools.getFullPath(customConf.getFileUrl(), doctor.getHeadPhoto()));
        jsonObject.put("patientName", patient.getName());
        jsonObject.put("msgType", "10016");
        jsonObject.put("origin", "1");
        jsonObject.put("patientId", patient.getId());
        jsonObject.put("askType", sendScheduleIMAO.getAskType());
        jsonObject.put("patientOnlineOrderId", sendScheduleIMAO.getPatientOnlineOrderId());
        chatMessageService.sendMessageByType(jsonObject);
        // 推送IM系统消息
        userApManager.sendSystemMessage(orderReg.getDoctorId(), patient.getPatientUserId(), "4");
        userApManager.sendSystemMessage(orderReg.getDoctorId(), patient.getId(), "4");
        return ResultBuilder.success(null);
    }

    @ApiOperation("根据patientOnlineOrderId查询详细信息")
    @Log(source = LogSourceEnum.APP, type = LogTypeEnum.UPDATE, desc = "根据patientOnlineOrderId查询详细信息")
    @PostMapping("queryPatientOnlineOrderDetail")
    public ResultDTO<Object> queryPatientOnlineOrderDetail(@RequestBody SendScheduleIMAO sendScheduleIMAO) throws Exception {
        // 判断参数是否为空
        CommonTool.checkObj(sendScheduleIMAO.getPatientOnlineOrderId(), "90000007");
        // 判断订单是否为空
        OnlineSession onlineSession = onlineSessionService.getOnlineSessionByPatientOnlineOrderId(sendScheduleIMAO.getPatientOnlineOrderId());
        CommonTool.checkObj(onlineSession, "90000007");
        // 判断用户是否为空
        PatientUser patientUser = patientUserService.findById(onlineSession.getPatientUserId());
        CommonTool.checkObj(onlineSession, "90000007");
        Map<String, Object> result = new HashMap<>();
        result.put("patientOnlineOrderId", onlineSession.getPatientOnlineOrderId());
        result.put("patientId", onlineSession.getPatientId());
        result.put("patientName", onlineSession.getPatientName());
        result.put("sessionStatus", onlineSession.getSessionStatus());
        result.put("headUrl", customConf.getFileUrl() + patientUser.getHeadPhoto());
        return ResultBuilder.success(result);
    }
}
